
#include <stdlib.h>
#include "que.h"

int TestEnqueDeque();
int TestPeek();
int TestPeekReset();

int main(int argc, char** argv) {
    printf("\n\n--------------\n");
    printf("queTest\n");
   
    int i;
    i = TestEnqueDeque();
    printf("TestEnqueDeque: %s\n",(i?"SUCCESS":"FAILED"));
    
    i =  TestPeek();
    printf("TestPeek: %s\n",(i?"SUCCESS":"FAILED"));
    
    i = TestPeekReset();
    printf("TestPeekReset: %s\n",(i?"SUCCESS":"FAILED"));
    
    return 0; 
}
int TestEnqueDeque(){
    que Q;
    int success = 1;
    int i,temp;
    uint8_t command[8] = {10,48,49,50,51,52,53,54};
     
    makeEmpty(&Q);


    for (i=0; i<6; ++i){
        enque(&Q, command[i]);
    }
    
    for (i=0; i<6; ++i){
        temp = deque(&Q);
        if (temp!=command[i]){
            success = 0;
        }
    }
    
    for (i=0; i<8; ++i){
        enque(&Q,command[i]);
    }
    
    for (i=0; i<6; ++i){
        temp = deque(&Q);
        if (temp!=command[i+2]){
            success = 0;
        }
    }
    
    return success;
}

int TestPeek() {
    que Q;
    int success = 1;
    int i,j,temp;
    uint8_t command[8] = {10,48,49,50,51,52,53,54};
    
    makeEmpty(&Q);
    
    for (i=0; i<6; ++i){
        enque(&Q,command[i]);
    }
      
    for (j=0; j<10; ++j){
    for (i=0; i<6; ++i){
        temp = peek(&Q);
        if (temp!=command[i]){
            success = 0;
        }
    }
    }

    return success;
}

int TestPeekReset(){
    que Q;
    int success = 1;
    int i,temp,temp2;
    uint8_t command[8] = {10,48,49,50,51,52,53,54};
      
    makeEmpty(&Q); 
    
    for (i=0; i<6; ++i){
        enque(&Q,command[i]);
    }
    
    temp = peek(&Q);
    temp = peek(&Q);
    
    peekReset(&Q);
    
    temp2 = peek(&Q);
    temp2 = peek(&Q);
    
    if (temp!=temp2){
        success = 0;
    }
    
    //printQue(Q);
    return success;

}

